<template>
  <div class="app-container">
    <div class="nav">
      <ul class="tab-tilte">
        <li :class="item.id===navIndex?'active':''" v-for="item in navList" :key="item.id" @click="switchTab(item)">{{item.txt}}</li>
      </ul>
      <el-button type="primary" @click="wipedata()" class="wipedata">清空数据</el-button>
    </div>
    <div class="table-container" style="position: relative;">
      <el-row :gutter="20" v-for="(item,index) in list" :key="index" v-if="list&&list.length">
        <el-col :span="4">
          <div class="grid-content bg-purple">
            <p class="title">销售额（元）</p>
            <p class="price">{{item.sales}}</p>
            <p class="info">
              <span>游客销售&nbsp;{{item.visitorSales}}</span>
              <br>
              <span>会员销售&nbsp;{{item.memberSales}}</span>
              <br>
              <span>渠道销售&nbsp;{{item.agentSales}}</span>
            </p>
          </div>
        </el-col>
        <el-col :span="4">
          <div class="grid-content bg-purple">
            <p class="title">返佣</p>
            <p class="price">10,000.00</p>
            <p class="info">
              <span>会员销售 4,000.00</span>
              <br>
              <span>返佣比例 15%</span>
              <br>
              <span>&nbsp;</span>
            </p>
          </div>
        </el-col>
        <el-col :span="4">
          <div class="grid-content bg-purple">
            <p class="title">积分发放</p>
            <p class="price">10,000.00</p>
            <p class="info">
              <span>1积分=1元人民币</span>
              <br>
              <span>&nbsp;</span>
              <br>
              <span>&nbsp;</span>
            </p>
          </div>
        </el-col>
        <el-col :span="4">
          <div class="grid-content bg-purple">
            <p class="title">进货金额(元)</p>
            <p class="price">10,000.00</p>
            <p class="info">
              <span>发布商品的总成本金额</span>
              <br>
              <span>&nbsp;</span>
              <br>
              <span>&nbsp;</span>
            </p>
          </div>
        </el-col>
        <el-col :span="4">
          <div class="grid-content bg-purple">
            <p class="title">毛利润（元）</p>
            <p class="price">10,000.00</p>
            <p class="info">
              <span>
                本月销售额 减去
                - 本月返佣
                -本月积分发放
                - 本月进货金额
              </span>
              <br>
              <span class="tips">仅统计填写成本价的商品</span>
            </p>
          </div>
        </el-col>
      </el-row>
      <el-row v-if="list.length==0" style="position: absolute;left: 50%;top: 50%;-webkit-transform: translate(-50%,-50%);transform: translate(-50%,-50%);color: #909399;">暂无数据</el-row>
    </div>
    <!-- <p v-show="nodatashow">没有更多了</p> -->
  </div>
</template>

<script>
const defaultListQuery = {
  dateType: 1,
  merchantId: 1
};
import { fetchList, wipedata } from "@/api/business";
export default {
  data() {
    return {
      navIndex: 1,
      listQuery: Object.assign({}, defaultListQuery),
      userInfo: JSON.parse(localStorage.getItem("userInfo")),
      navList: [
        {
          id: 1,
          txt: "本月度",
          dateType: "1"
        },
        {
          id: 2,
          txt: "本季度",
          dateType: "2"
        },
        {
          id: 3,
          txt: "本年度",
          dateType: "3"
        }
      ],
      list: null,
      nodatashow: false
    };
  },
  created() {
    this.getList();
  },
  methods: {
    // 数据渲染
    getList() {
      this.listLoading = true;
      fetchList(this.listQuery).then(response => {
        console.log(response.data.length, 222222222222222222222);
        if (response.data.length == 0) {
          this.list = [];
          this.nodatashow = true;
        } else {
          this.list = response.data;
        }
      });
    },
    // 清空数据
    wipedata() {
      let params = new URLSearchParams();
      params.append("merchantId ", 1);
      wipedata().then(response => {
        console.log(response.data);
        if (response.code == 0) {
          this.$message({
            message: "清除成功",
            type: "success",
            duration: 1000
          });
          this.getList();
        }
      });
    },

    // 切换导航
    switchTab(item) {
      this.navIndex = item.id;
      this.listQuery.dateType = item.dateType;
      this.getList();
    }
  }
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.app-container {
  background: #fff;
  min-height: 500px;
  .nav {
    margin-bottom: 10px;
    border-bottom: 2px solid #f1f1f1;
    display: flex;
    justify-content: space-between;
    box-sizing: border-box;
    .tab-tilte {
      width: 50%;
      height: 40px;
      li {
        float: left;
        width: 25%;
        padding: 10px 0;
        text-align: center;
        cursor: pointer;
      }
    }
    .tab-tilte .active {
      border-bottom: 2px solid #09f;
      color: #000;
      font-weight: 600;
    }
    .wipedata {
      height: 48px;
    }
  }
  .el-row {
    margin-bottom: 20px;
    &:last-child {
      margin-bottom: 0;
    }
    .bg-purple {
      border: 1px solid #ccc;
      padding: 10px;
      box-sizing: border-box;
      border-radius: 4px;
      .title {
        font-size: 14px;
      }
      .price {
        font-size: 16px;
        font-weight: 600;
        border-bottom: 1px solid #ccc;
        line-height: 32px;
        box-sizing: border-box;
      }
      .info {
        font-size: 14px;
        color: #7d7c7c;
        span {
          line-height: 32px;
        }
        span.tips {
          font-size: 12px;
          color: #ff0000;
        }
      }

      .Seedetails {
        cursor: pointer;
        color: #0068b7;
        text-align: center;
      }
    }
    .bg-purple-dark {
      border: 1px solid #ccc;
      padding: 0 10px;
      box-sizing: border-box;
      border-radius: 4px;
      h4 {
        font-size: 13px;
      }
      ul {
        overflow: hidden;
        li {
          display: inline-flex;
          margin: 0;
          padding: 0;
          width: 14%;
          text-align: left;
          float: left;
          line-height: 36px;
          color: #666;
        }
      }
    }
  }
}
</style>
